package com.lingshu.app.repository;

import androidx.lifecycle.MutableLiveData;

import com.lingshu.app.config.App;
import com.lingshu.app.database.bean.WallPaperBean;
import com.lingshu.app.network.CustomDisposable;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Flowable;

/**
 * 获取PictureViewActivity所需数据
 */
public class PictureRepository {
    public final MutableLiveData<String> failed = new MutableLiveData<>();
    private final MutableLiveData<List<WallPaperBean>> wallPaper = new MutableLiveData<>();

    @Inject
    PictureRepository() {
    }

    public MutableLiveData<List<WallPaperBean>> getWallPaper() {
        Flowable<List<WallPaperBean>> listFlowable = App.getDb().wallPaperDao().getAll();
        CustomDisposable.addDisposable(listFlowable, wallPapers -> {
            if (wallPapers.size() > 0) {
                wallPaper.postValue(wallPapers);
            } else {
                failed.postValue("暂无数据");
            }
        });
        return wallPaper;
    }
}